package com.example.yt_app.Activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.yt_app.Activity.BaseActivity.BaseActivity;
import com.example.yt_app.Activity.BaseActivity.SwipeBackBaseActivity;
import com.example.yt_app.AppManager;
import com.example.yt_app.R;

import com.example.yt_app.Urils.SPTool;
import com.example.yt_app.Urils.State;
import com.example.yt_app.Urils.Utils;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;
import me.imid.swipebacklayout.lib.app.SwipeBackActivityBase;

/**
 *
 * @author dell
 * @date 2021/7/21
 */
@SuppressWarnings("ALL")
public class SetActivity extends SwipeBackBaseActivity {


    @BindView(R.id.detail_toolbar)
    Toolbar toolbar;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.set_bt)
    Button set_bt;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.key)
    EditText Key;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.sb_id)
    EditText Sb_id;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.sb_ids)
    EditText Sb_ids;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.src)
    ImageView Src;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.src_1)
    ImageView Src1;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    @BindView(R.id.src_2)
    ImageView Src2;

    private String key;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    private String sb_id;
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    private String sb_ids;





    @Override
    protected int getLayoutId() {
        return R.layout.set_sb_activity;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(toolbar).init();
        //隐藏状态栏
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_STATUS_BAR).init();
        ImmersionBar.with(this).titleBar(R.id.detail_toolbar).keyboardEnable(true).init();
    }
    @Override
    protected void initView() {
        AppManager.getInstance().addActivity(this);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }


    }

    @Override
    protected void initData() {
        State.DeviceIDs = SPTool.getInstance(this).getString("DeviceIDs","735471469");
        State.ApiKey = SPTool.getInstance(this).getString("Api_Key","FN8vCnpwAjyjTV2m1y=zpL451i4=");
        if (State.DeviceIDs != ""){
            Sb_ids.setText(State.DeviceIDs);
        }
        if (State.ApiKey != ""){
            Key.setText(State.ApiKey);
        }
        State.OTHER = false;
    }


    @Override
    protected SwipeBackLayout getSwipeBackLayout(int layoutId) {
        return null;
    }




    @Override
    protected void setListener() {
        //toolbar返回按钮监听
        toolbar.setNavigationOnClickListener(v ->finish() );
    }
    @SuppressWarnings("AlibabaSwitchStatement")
    @OnClick(R.id.set_bt)
    public void onClick(View v) {
        //noinspection AlibabaSwitchStatement
        switch (v.getId()){

            case R.id.set_bt:
                DateYanZheng();

                break;
        }
    }
    /**
     * 数据验证
     * */
    @SuppressWarnings({"AlibabaLowerCamelCaseVariableNaming", "AlibabaUndefineMagicConstant", "AlibabaRemoveCommentedCode"})
    private void DateYanZheng(){
        String s = "FN8vCnpwAjyjTV2m1y=zpL451i4=";
        key = Key.getText().toString();
        sb_id = Sb_id.getText().toString();
        sb_ids = Sb_ids.getText().toString();
        //截取之后的字符

//        String keySum = key.substring(0,key.indexOf("="));
        //noinspection AlibabaUndefineMagicConstant
        if (key.length() >12 && key != ""){
            /*设置key*/
            SPTool.getInstance(this).putString("Api_Key",key);

            Src.setImageResource (R.mipmap.right);
//            if (sb_id.length() >=9 && sb_id != ""){
//                sb_id = State.DeviceID;
//                Src1.setImageResource (R.mipmap.right);
//                SPTool.getInstance(this).putString("DeviceIDs",sb_ids);
//            }else {
//                showMessage("ID格式有误");
//                Src1.setImageResource (R.mipmap.cuo);
//            }
            if (sb_ids != ""){
                //noinspection AlibabaUndefineMagicConstant
                if (sb_ids.length() >=8 ){
                    Src2.setImageResource (R.mipmap.right);
                    SPTool.getInstance(this).putString("DeviceIDs",sb_ids);
                }else {
                    showMessage("ID格式有误");
                    Src2.setImageResource (R.mipmap.cuo);
                }
            }else {
                Src2.setImageResource (R.mipmap.wu);
            }

        }else
            {
                Src.setImageResource (R.mipmap.cuo);
                showMessage("API_KEY格式输入有误");

        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        State.OTHER = true;
    }
}
